package com.sky.mapper;

import com.sky.annotation.AutoFill;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Setmeal;
import com.sky.entity.SetmealDish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishItemVO;
import com.sky.vo.SetmealVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface SetmealMapper {

    /**
     * 动态条件查询套餐
     * @param setmeal
     * @return
     */
    List<Setmeal> list(Setmeal setmeal);

	/**
     * 根据套餐id查询菜品选项
     * @param setmealId
     * @return
     */
    List<DishItemVO> getDishItemBySetmealId(Long setmealId);

    /**
     * 根据条件统计套餐数量
     * @param setmealPageQueryDTO
     * @return
     */
    int total(SetmealPageQueryDTO setmealPageQueryDTO);

    /**
     * 插入套餐信息
     * @param setmeal
     */
    void saveSetmeal(Setmeal setmeal);

    /**
     * 插入套餐菜品关系
     * @param setmealDishes
     */
    void saveSetmealDish(List<SetmealDish> setmealDishes);

    List<SetmealVO> pageQuery(SetmealPageQueryDTO setmealPageQueryDTO);

    @Update("update setmeal set status = #{status} where id = #{id}")
    void setStatus(long status,Long id);

    @Select("select * from setmeal where id = #{id}")
    SetmealVO getById(Long id);

    @Select("select * from setmeal where id = #{id}")
    Setmeal getSetmealById(Long id);

    @AutoFill(value = OperationType.UPDATE)
    void update(Setmeal setmeal);

    @Select("delete from setmeal where id = #{id}")
    void deleteBySetmealId(Long id);

    @Select("delete from setmeal_dish where setmeal_id = #{id}")
    void deleteBySetmealId_Dish(Long id);

    @Select("select * from setmeal_dish where setmeal_id = #{id}")
    List<SetmealDish> getSetmealDishBySetmealId(Long id);


    void deleteBySetmealIds(List<Long> ids);

    List<SetmealVO> getSetmealByCategoryId(int categoryId);

    @Select("select * from setmeal where category_id = #{categoryId} and status = 1")
    List<Setmeal> getSetmealByCategoryIdStatus(int categoryId);

    @Select("select * from setmeal_dish where dish_id = #{id}")
    List<SetmealDish> getSetmealDish(Long id);

    @Select("select * from setmeal where category_id = #{id}")
    List<Setmeal> getSetmeal(Long id);

    @Select("select * from setmeal where category_id = #{categoryId}")
    List<SetmealVO> getSetmealVO(int categoryId);
}
